package map.function;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public final class FunctionTest {
    private String s;
    public FunctionTest() {
    }
    public FunctionTest(String s) {
        this.s = s;
    }
    public Integer getS() {
        return Integer.valueOf(this.s);
    }

    public static void main(String[] args) {
//        new FunctionTest().go();
        new FunctionTest("99999").testf(FunctionTest::sayTest);
    }
    
    public void testf(Consumer<? super FunctionTest> handleM) {
        handleM.accept(this);
    }
    public void sayTest() {
        System.out.println(this.getS());
    }

    public void go() {
        Map<Key, Value> map = new HashMap<>();
        map.computeIfAbsent(new Key(99), Value::getDefaultV);
        List<String> list = new ArrayList<>();
        list.add("111");
        list.add("222");
        list.add("333");
        List<Integer> list2 = list.stream().map(FunctionTest::string2Integer)
                .collect(Collectors.toList());
        list2.forEach(System.out::println);
        List<Integer> list21 = list.stream().map(item -> FunctionTest.string2Integer(item))
                .collect(Collectors.toList());
        list21.forEach(item -> System.out.println(item));
        List<Integer> list3 = list.stream()
                .map(new FunctionTest()::string2Integer2)
                .collect(Collectors.toList());
        list3.forEach(System.out::println);
        List<FunctionTest> listTest = new ArrayList<>();
        listTest.add(new FunctionTest("111"));
        listTest.add(new FunctionTest("222"));
        listTest.add(new FunctionTest("333"));
        List<Integer> list4 = listTest.stream().map(FunctionTest::getS)
                .collect(Collectors.toList());
        list4.forEach(item -> {System.out.println(item);});
    }

    public static Integer string2Integer(String str) {
        return Integer.valueOf(str);
    }
    public Integer string2Integer2(String str) {
        return Integer.valueOf(str);
    }
}
